package com.nycreativity.elecreativity.service.impl

import com.baomidou.mybatisplus.extension.plugins.pagination.Page
import com.nycreativity.elecreativity.entity.po.Activity
import com.nycreativity.elecreativity.mapper.ActivityMapper
import com.nycreativity.elecreativity.service.ActivityService
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
import com.nycreativity.elecreativity.entity.param.activity.ActivityAddParam
import com.nycreativity.elecreativity.entity.param.activity.ActivityQueryParam
import com.nycreativity.elecreativity.entity.vo.PageDataVO
import com.nycreativity.elecreativity.entity.vo.activity.ActivityVO
import com.nycreativity.elecreativity.mapper.vomapper.ActivityVOMapper
import com.nycreativity.elecreativity.util.KtWrapperUtil
import com.nycreativity.elecreativity.util.MappingUtil
import com.nycreativity.elecreativity.util.PageUtil
import org.springframework.stereotype.Service
import javax.annotation.Resource

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sxt && ttxxi
 * @since 2021-03-10
 */
@Service
class ActivityServiceImpl : ServiceImpl<ActivityMapper, Activity>(), ActivityService {

    @Resource
    lateinit var activityMapper: ActivityMapper

    @Resource
    lateinit var activityVOMapper: ActivityVOMapper

    companion object {
        private val ORDER_COLUMN = arrayOf("create_time")
    }

    override fun addActivity(activityAddParam: ActivityAddParam): Boolean {
        val activity = MappingUtil.getMappingObject(activityAddParam, Activity::class.java)
        activity.create()
        return activityMapper.insert(activity) > 0
    }

    override fun queryActivity(activityQueryParam: ActivityQueryParam): PageDataVO<ActivityVO> {
        val queryWrapper = KtWrapperUtil.getKtQueryWrapper<ActivityVO, ActivityQueryParam>(activityQueryParam)
        queryWrapper.orderByDesc(ActivityVO::createTime)
//        queryWrapper.lambda().eq(ActivityVO::content, "123")
        val page = Page<ActivityVO>(activityQueryParam.currentPage.toLong(), activityQueryParam.pageSize.toLong())
        val selectPage = activityVOMapper.selectPage(page, queryWrapper)
        return PageUtil.convert(selectPage)
    }

}

